from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import  Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

# 先初始化WebDriver
driver = webdriver.Chrome(executable_path='C:\\Program Files\\Google\Chrome\\Application\\chromedriver.exe')

# 打开某个页面
driver.get('https://www.baidu.com/')

# 获取百度的搜索输入框
input = driver.find_element(By.ID,'kw')
# 输入
input.send_keys('Python 教程')

# 隐形等待网页元素加载完毕
driver.implicitly_wait(10)   # time.sleep(10)


# 显示等待网页元素加载完毕
# wait = WebDriverWait(driver,10)   # 设置超时时间10s
# 显示等待获取搜索按钮
# submit = wait.until(EC.element_to_be_clickable((By.ID,'su')))
submit = driver.find_element(By.ID,'su')
# 点击
submit.click()


print(driver.page_source)  # 打印网页源代码
print(driver.get_cookies())  # 打印cookie


# 释放资源
driver.close()


